/*
   Copyright (c) [2023] [魔凤啸天]
   [MFUI] is licensed under Mulan PSL v2.
   You can use this software according to the terms and conditions of the Mulan PSL v2. 
   You may obtain a copy of Mulan PSL v2 at:
            http://license.coscl.org.cn/MulanPSL2 
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
   See the Mulan PSL v2 for more details.  
*/
#pragma once
#include "core.hpp"

namespace MFUI{
	class Button:public CacheNode{
		public:
		enum State{
			state_released=0,//默认
			state_on,
			state_pressed
		};
		private:
		State state;
		bool entered;//鼠标进入时设为true 离开时设为false
		public:
		static void mousebuttondowncallback(Window*,Button*,SDL_Event*);
		static void mousebuttonupcallback(Window*,Button*,SDL_Event*);
		static void mousemotioncallback(Window*,Button*,SDL_Event*);
		protected:
		virtual ~Button()override;
		//用于响应UI绘制变更 默认调用pressed(w)
		virtual void _pressed(Window* w,SDL_FPoint p);
		//用于响应UI绘制变更 默认调用released(w)
		virtual void _released(Window* w,SDL_FPoint p);
		public:
		void onadd(Window* w)override;
		void onremove(Window* w)override;
		Button();
		Button(std::initializer_list<Node*>& children);
		bool ismouseentered();
		//用于实现自定义逻辑
		virtual void pressed(Window* w,SDL_FPoint& p);
		//用于实现自定义逻辑
		virtual void released(Window* w,SDL_FPoint& p);
		virtual void mouseentered(Window* w);
		//进入期间被移出window也会触发
		virtual void mouseexited(Window* w);
		//p为绝对位置
		virtual void mousemove(Window* w,SDL_FPoint p);
		State getstate()const;
	};
}